<?php

include('lib/src/config.php');

require_once "lib/src/apiClient.php";
require_once "lib/src/contrib/apiCalendarService.php";

$calID = 'stanley5.com_p13b36incoflgq8076i6lvqk0k@group.calendar.google.com';  //Family Tree

if (isset($_GET['id'])) {
	$evtID = $_GET['id'];
} else {
	echo "No event ID passed.\n";
	exit;
}

session_start();

//  AUTHENITCATE

$apiClient = new apiClient();
$apiClient->setUseObjects(true);
$service = new apiCalendarService($apiClient);

if (isset($_SESSION['oauth_access_token'])) {
  $apiClient->setAccessToken($_SESSION['oauth_access_token']);
} else {
  $token = $apiClient->authenticate();     //has to be failing here. This is where it all happens and the token is empty
  $_SESSION['oauth_access_token'] = $token;
}

?>

<html>

<body>
<p>
Here is the event for ID <?php print($evtID); ?>:
</p>

<pre>
<?php

//  RETRIEVE EVENT

$event = $service->events->get($calID, $evtID);

//  OUTPUT

print_r($event->start->date);
print(" $event->summary \n");
//print_r($event->getWhen());

?>
</pre>

<p>Details:</p>
<pre>

<?php
print_r($event);
?>

</pre>

</body>
</html>